package br.com.ftt.database;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import br.com.fsa.aplication.Model.bean.Logistica;
import br.com.ftt.exception.ConectionException;
import br.com.ftt.util.HibernateUtil;
import br.com.ftt.util.Util;

public class LogisticaDAO extends DaoGenericoImpl<Logistica>
{

	public Logistica findLogisticaByCodigo(long id) throws ConectionException
	{
		Session session = null;
		try
		{
			session = HibernateUtil.getSession().openSession();
			return (Logistica) session.createCriteria(Logistica.class)
					.add(Restrictions.eq("codLog", id)).uniqueResult();
		}
		catch (HibernateException e)
		{
			Util.gravaLog(e.getMessage());
			throw new ConectionException(e.getMessage());

		}
		catch (ConectionException e)
		{
			Util.gravaLog(e.getMessage());
			throw e;
		}
		finally
		{
			if (session.isOpen())
			{
				session.close();
			}
		}

	}

}
